package com.ruoyi.project.stop.controller;

import java.util.List;

import com.ruoyi.project.stop.domain.AppVersion;
import com.ruoyi.project.stop.domain.StopRecord;
import com.ruoyi.project.stop.service.IAppVersionService;
import io.swagger.annotations.ApiOperation;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.web.page.TableDataInfo;

/**
 * app版本发布Controller
 *
 * @author ruoyi
 * @date 2025-04-08
 */
@RestController
@RequestMapping("/stop/version")
public class AppVersionController extends BaseController
{
    private String prefix = "stop/version";

    @Autowired
    private IAppVersionService appVersionService;

    @GetMapping()
    public String version()
    {
        return prefix + "/version";
    }

    @ApiOperation("获取最新急停按钮信息")
    @GetMapping("/getLastOne")
    public AjaxResult getInfo()
    {
        AppVersion appVersion = appVersionService.selectAppVersionById(1L);
        if (appVersion !=null)
        {
            return success(appVersion);
        }
        else
        {
            return error("数据不存在");
        }
    }

    /**
     * 查询app版本发布列表
     */
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(AppVersion appVersion)
    {
        startPage();
        List<AppVersion> list = appVersionService.selectAppVersionList(appVersion);
        return getDataTable(list);
    }

    /**
     * 导出app版本发布列表
     */
    @Log(title = "app版本发布", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(AppVersion appVersion)
    {
        List<AppVersion> list = appVersionService.selectAppVersionList(appVersion);
        ExcelUtil<AppVersion> util = new ExcelUtil<AppVersion>(AppVersion.class);
        return util.exportExcel(list, "app版本发布数据");
    }

    /**
     * 新增app版本发布
     */
    @RequiresPermissions("system:version:add")
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存app版本发布
     */
    @RequiresPermissions("system:version:add")
    @Log(title = "app版本发布", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(AppVersion appVersion)
    {
        return toAjax(appVersionService.insertAppVersion(appVersion));
    }

    /**
     * 修改app版本发布
     */
    @RequiresPermissions("system:version:edit")
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        AppVersion appVersion = appVersionService.selectAppVersionById(id);
        mmap.put("appVersion", appVersion);
        return prefix + "/edit";
    }

    /**
     * 修改保存app版本发布
     */
    @RequiresPermissions("system:version:edit")
    @Log(title = "app版本发布", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(AppVersion appVersion)
    {
        return toAjax(appVersionService.updateAppVersion(appVersion));
    }

    /**
     * 删除app版本发布
     */
    @RequiresPermissions("system:version:remove")
    @Log(title = "app版本发布", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(appVersionService.deleteAppVersionByIds(ids));
    }
}
